package procilege.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.solr.util.OpenBitSet;

import procilege.lang.Name;
import procilege.lang.PrivExprComposition;
import procilege.lang.PrivExprElement;
import procilege.lang.PrivilegeForm;
import procilege.lang.PrivilegeFormTerm;
import procilege.lang.Substitution;

public class PrivilegeFormImpl implements PrivilegeForm {

	Name name;

	PrivExprElement expr;
	
	PrivExprComposition expandedExpr;

	boolean isDirty = true;

	Map<OpenBitSet, Collection<PrivilegeFormTerm>> functionMap = new HashMap<OpenBitSet, Collection<PrivilegeFormTerm>>();

	OpenBitSet reducedFunctions = new OpenBitSet();
	
	PrivExprElement[] expandedTerms;
	Substitution[] substitutions;

	public PrivilegeFormImpl(Name name) {

		this.name = name;
	}

	public PrivilegeFormImpl(PrivExprElement expr) {

		this.expr = expr;
	}

	public Iterator<PrivilegeFormTerm> termsIterator() {
		
		ArrayList<PrivilegeFormTerm> list = new ArrayList<PrivilegeFormTerm>();
		for (Collection<PrivilegeFormTerm> ts : functionMap.values()) {
			list.addAll(ts);
		}
		return list.iterator();
	}
}